package company.permissionsystem.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import company.permissionsystem.model.entity.Position;
import company.permissionsystem.model.entity.SysUser;
import company.permissionsystem.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class PositionController {

    @Autowired
    private PositionService positionService;

    @GetMapping("/position")
    public String positionIndex(@RequestParam(defaultValue = "1", value = "pageNum") Integer pageNum, Model model) {
        PageHelper.startPage(pageNum, 8);
        List<Position> positionList = positionService.findAllPositon();
        PageInfo<Position> lists = new PageInfo<>(positionList);
        model.addAttribute("positions", lists);
        return "position/position";
    }

    @GetMapping("/position/{id}")
    public String findPositionEmployee(@RequestParam(defaultValue = "1", value = "pageNum") Integer pageNum,
                                       Model model, @PathVariable Long id) {
        PageHelper.startPage(pageNum, 8);
        List<SysUser> sysUsers = positionService.findEmployeeByPositionId(id);
        PageInfo<SysUser> lists = new PageInfo<>(sysUsers);
        model.addAttribute("users", lists);
        return "employee/employee-list";
    }


}
